import { onMounted, ref, onBeforeUnmount } from 'vue'
export const useWindowScroll = () => {
  const y = ref(0)
  const x = ref(0)
  const onScroll = () => {
    y.value = document.documentElement.scrollTop
    x.value = document.documentElement.scrollLeft
    // console.dir(window.pageXOffset)
  }
  onMounted(() => {
    window.addEventListener('scroll', onScroll)
  })
  onBeforeUnmount(() => {
    window.removeEventListener('scroll', onScroll)
  })
  return {
    x,
    y
  }
}
